package it.eng.get.pdfwe.fillers;

import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

public abstract class ModelFiller {

	public static final String _jasperreporfiller$datasource="_jasperreporfiller$datasource";

	protected HttpServletRequest request;
	protected HttpSession session;
	protected List params;
	
	public ModelFiller(List params) {
		this.params = params;
	}

	public ModelFiller(HttpSession session) throws Exception {
		if (session==null) throw new Exception("Session e' null");
		this.session = session;
	}
	
	
	public ModelFiller(HttpServletRequest request) throws Exception {
		if (request==null) throw new Exception("Request e' null");
		this.request = request;
	}

	protected String _getParamFromRequest(String key) throws Exception {
		String param = request.getParameter(key);
		if (param==null) throw new Exception("Inserire nella request il parametro " + key);
		return param;
	}

	protected Object _getObjectFromSession(Class cl,String key) throws Exception {
		try {
			return cl.cast(request.getSession().getAttribute(key));
		} catch (Exception e) {
			throw new Exception("Inserire in sessione un oggetto di tipo " + cl.getName() + 
					" con chiave " + key);
		}
	}

//	private JRFillerBean _rptPratica(Object[] reportParams) throws Exception {
//		HashMap< String, Object> params=new HashMap<String, Object>();
//		params.put("modelloUnico", _getObject(ModelloUnicoDocument.ModelloUnico.class, _rptPratica$ModelloUnico)); 
//		params.put("datiPost", _getObject(HrefDocument.Href.class, _rptPratica$datiPostHref));
//		params.put("SUBREPORT_DIR", _getObject(String.class, _rptPratica$subreportDir));
//		params.put("sdf", _getObject(java.text.SimpleDateFormat.class, _rptPratica$sdf));
//		params.put("logoRomaUrl", _getObject(String.class, _rptPratica$logoRomaUrl));
//		params.put("logoStemmaRoma", _getObject(String.class, _rptPratica$logoStemmaRoma));
//		params.put("strutturaAppartenenza", _getObject(String.class, _rptPratica$strutturaAppartenenza));
//		JRDataSource ds = (JRDataSource)_getObject(JRDataSource.class, _jasperreporfiller$datasource);
//		return new JRFillerBean(params, ds);
//	}

//	private JRFillerBean _stampaMercatoPosteggi(Object[] reportParams) throws Exception {
//		HashMap< String, Object> params=new HashMap<String, Object>();
//		params.put("modelloUnico", _getObject(ModelloUnicoDocument.ModelloUnico.class, _rptPratica$ModelloUnico)); 
//		params.put("datiPost", _getObject(HrefDocument.Href.class, _rptPratica$datiPostHref));
//		params.put("SUBREPORT_DIR", _getObject(String.class, _rptPratica$subreportDir));
//		params.put("sdf", _getObject(java.text.SimpleDateFormat.class, _rptPratica$sdf));
//		params.put("logoRomaUrl", _getObject(String.class, _rptPratica$logoRomaUrl));
//		params.put("logoStemmaRoma", _getObject(String.class, _rptPratica$logoStemmaRoma));
//		params.put("strutturaAppartenenza", _getObject(String.class, _rptPratica$strutturaAppartenenza));
//		JRDataSource ds = (JRDataSource)_getObject(JRDataSource.class, _jasperreporfiller$datasource);
//		return new JRFillerBean(params, ds);
//	}

	public abstract Object getData()  throws Exception;
	
	
//	public JRFillerBean getData(String reportName,Object[] reportParams) throws Exception {
//		if (reportName==null) throw new Exception("Il nome del report e' null");
//		if (reportName.indexOf("rptPratica.jasper")>-1) {
//			return _rptPratica(reportParams);
//		}
//		if (reportName.indexOf("StampaMercatoPosteggi.jasper")>-1) {
//			return _stampaMercatoPosteggi(reportParams);
//		}
//		
//
//
//
//		throw new Exception("Non e' stato possibile popolare il report " + reportName);
//	}


}
